package com.lu.client.zk;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * zk 的工厂方法
 * 用于建立与 zk 的连接
 * @author xiaolu
 * @version 1.0
 * @date 2021-02-02 21:43
 */
public class ZookeeperFactory {

    public static CuratorFramework client;

    public static CuratorFramework create() {

        if (client == null) {
            ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
            client = CuratorFrameworkFactory.newClient("localhost:2181", retryPolicy);
            client.start();
        }

        return client;
    }

    public static void main(String[] args) throws Exception {
        CuratorFramework client = create();
        client.create().forPath("/netty");
    }
}
